package com.itheima.web;

import com.itheima.pojo.User;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author 徐柯老师
 * @Description
 * @Tel/微信：15074816437
 * @Version 1.0
 **/
@Controller
public class UserController {

    @Autowired
    private IUserService userService;

    //todo :http://localhost:8080/vuessm/findUsers
    // 问题为什么要加，区别是什么？
    @ResponseBody
    @GetMapping("/findUsers")
    public List<User> findUsers(){
        return userService.findUsers();
    }


    //http://localhst:800/path?id=23&name=23
    @ResponseBody
    @GetMapping("/getUser/{id}")
    public User getUser(@PathVariable("id") Long id){
        return userService.getUser(id);
    }


    @ResponseBody
    @GetMapping("/getUser2")//getUser2?id=2
    public User getUser2(@RequestParam("id") Long id){
        return userService.getUser(id);
    }

    @ResponseBody
    @PostMapping("/saveUser")
    public int saveUser(@RequestBody User user){
        return userService.saveUser(user);
    }


    @ResponseBody
    @PostMapping("/updateUser")
    public int updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @ResponseBody
    @GetMapping("/deleteByid/{id}")
    public int deleteByid(@PathVariable("id") Long id){
        return userService.deleteById(id);
    }


}
